<template>
  <div id="luckysheet7">
    <el-form size="mini" :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="日期">
        <el-date-picker
          v-model="formInline.ynday"
          format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>

    <div id="luckysheet6"></div>
  </div>

</template>

<script>
import LuckyExcel from 'luckyexcel';
import {Message} from "element-ui";
import moment from "moment";

export default {
  name: "daySheet5",
  created() {
    this.init(moment().format('yyyy-MM-DD'));
  },
  methods: {
    onSubmit() {
      let s = !!this.formInline.ynday ? moment(this.formInline.ynday).format('yyyy-MM-DD') : moment().format('yyyy-MM-DD');
      this.init(s);
    },
    init(date) {
      this.axios.post('/jmreport/exportAllExcelStream', {
        "excelConfigId": "986436911500054528",
        "queryParam": {
          "pageNo": "1",
          "pageSize": 10,
          "currentPageNo": "1",
          "currentPageSize": 10,
          "ynday": date
        }
      }, {responseType: 'arraybuffer'}).then(res => {

        let blob = new Blob([res.data], {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});

        let file = new File([blob], "example.xlsx", {
          type: blob.type,
        });

        this.file = file;

        LuckyExcel.transformExcelToLucky(file, function (exportJson, luckysheetfile) {
            if (exportJson.sheets == null || exportJson.sheets.length === 0) {
              Message.warning("读取excel文件内容失败");
              return;
            }
            exportJson.sheets[0]["zoomRatio"] = 0.8;
            const options = {
              container: 'luckysheet6',
              showinfobar: false,
              data: exportJson.sheets,
              showsheetbar: false,
              sheetFormulaBar: false,
            };
            luckysheet.destroy()
            luckysheet.create(options);
          }, function (err) {
            Message.warning('Import failed. Is your fail a valid xlsx?');
          }
        );

      })
    },

  },
  data() {
    return {
      xs: null,
      fileList: [],
      file: null,
      autoGenerateColumns: false,
      spread: null,
      selectedFile: null,
      formInline: {
        ynday: (moment().format('yyyy-MM-DD'))
      }
    };
  },
  mounted() {
  },
}
</script>

<style scoped>
#luckysheet7, #luckysheet6 {
  margin: 0px;
  padding: 0px;
  position: relative;
  width: 100%;
  height: 100%;
  left: 0px;
  top: 0px;
}
</style>
